package com.daihou.utils;

import com.daihou.model.DHInterfaceAuth;

import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.stream.Collectors;

public class DHConfigFile {
    private static ResourceBundle bundle = ResourceBundle.getBundle("app_Pingfenka", Locale.CHINA);
    public static String getUrl(String name) {
        String address = bundle.getString("DaiHou_URL");
        String uri = "";
        String testUrl;
        //这里做个转换，把输入的 DAORU 转换为 daoru.uri
        String canshu = name.toLowerCase() + ".uri";
        uri = bundle.getString(canshu);
        testUrl = address + uri;
        return testUrl;
    }

    public static String getUrl(DHInterfaceAuth name) {
        String address = bundle.getString("DaiHou_URL");
        String uri = "";
        String testUrl;
        if (name == DHInterfaceAuth.AUTH) {
            uri = bundle.getString("auth.uri");
        }
        testUrl = address + uri;
        return testUrl;
    }

    public static String getUrl(String ipAdress, String configName, String testUrlName) {
        ResourceBundle bundle = ResourceBundle.getBundle(configName, Locale.CHINA);
        String address = bundle.getString(ipAdress);
        String testUrl;
        String preUrlName = testUrlName + ".uri";
        List<String> keys = bundle.keySet().stream().filter(s -> s.equalsIgnoreCase(preUrlName)).collect(Collectors.toList());
        String uri = bundle.getString(keys.get(0));
        testUrl = address + uri;
        return testUrl;
    }
}
